

di "************************************************************************************************"
di "*************************************** LOAD DATA ********** ***********************************"
di "************************************************************************************************"

u "$saveddata/RESTAT_replication_workerdata.dta", clear

cd $output_location

gl firm_controls multiplant fgn_ent  ln_age_ent
gl worker_controls age_ashe tenure_ashe tenure_ashe_sq skilled10 sex_ashe age_ashe_sex tenure_ashe_sex tenure_ashe_sq_sex skilled10_sex

*Restrict regression sample using firm characteristics
gen restrict_firm_reg = 1 if (!missing(cloud)) & !missing(fibre_L1) & !missing(dist_fibre_L1)  & !missing(multiplant) & !missing(fgn_ent) & !missing(age_ent)  & year >= 2007 & year <= 2016 & birth_ent <= 2008 & !missing(fibre_enable_year_ent)
label var restrict_firm_reg		"Firm regression sample"

di "************************************************************************************************"
di "*************************************** Table B1: Summary Statistics  **************************"
di "************************************************************************************************"
cap drop smpl
gen temp=1
foreach var in $firm_controls{
	replace temp=0 if missing(`var')
}
foreach var in $worker_controls{
	replace temp=0 if missing(`var')
}
foreach var of varlist lu_change change_D1_ashe cloud pcloud fibre_L1_sizepw pfibre_fibre_L1 pfibre_fibre_L1_sizew{
	replace temp=0 if missing(`var')
}
replace temp = 0 if !(birth_ent<2003 & (year == 2008 | year==2013 | year==2015) & restrict_firm_reg ==1 & ees_ent >5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu))
bysort luref: egen smpl=sum(temp)
replace smpl=0 if smpl == 1 | temp == 0 // drop singletons
replace smpl = 1 if smpl> 1 & !missing(smpl) & temp==1
drop temp

tabstat lu_change_D1_ashe hq_D1_ashe gr1_dist_lu cloud pcloud  fibre_L1 pfibre_fibre_L1 multiplant fgn_ent age_ent dist_fibre_L1 age_ashe tenure_ashe skilled10 sex_ashe if smpl==1, stats(n mean sd) 
tabstat $firm_controls  $worker_controls if smpl==1,  stats(n mean sd) 


di "************************************************************************************************"
di "*************************************** Table B2: Plant Switching  *****************************"
di "************************************************************************************************"

estimates drop _all
ivreghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates store s1
ivreghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates restore reghdfe_first1
estimates store f1
ivreghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates restore reghdfe_first2
estimates store pf1

estimates drop _all
ivreghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates store s2
ivreghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates restore reghdfe_first1
estimates store f2
ivreghdfe lu_change_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates restore reghdfe_first2
estimates store pf2


ivreghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates store s3
ivreghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates restore reghdfe_first1
estimates store f3
ivreghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates restore reghdfe_first2
estimates store pf3

ivreghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates store s4
ivreghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates restore reghdfe_first1
estimates store f4
ivreghdfe hq_D1_ashe $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates restore reghdfe_first2
estimates store pf4


ivreghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates store s5
ivreghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates restore reghdfe_first1
estimates store f5
ivreghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year luref) cluster(luref)  
estimates restore reghdfe_first2
estimates store pf5

ivreghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates store s6
ivreghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates restore reghdfe_first1
estimates store f6
ivreghdfe gr1_dist_lu $firm_controls $worker_controls (cloud pcloud = fibre_L1 fibre_L1_sizew pfibre_fibre_L1 pfibre_fibre_L1_sizew) if birth_ent < 2003 &(year == 2008 | year == 2013 | year == 2015) & restrict_firm_reg == 1 &  ees_ent > 5 & ees_ent<ees_ent_p95 & !missing(fibre_enable_year_lu), absorb(year piden luref) cluster(luref)  
estimates restore reghdfe_first2
estimates store pf6

esttab s* using "TableB2_Second_Stage.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
esttab f* using "TableB2_First_Stage_Cloud.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)
esttab pf* using "TableB2_First_Stage_PlantCloud.csv", replace cells(b(star fmt(%9.3f)) se(par fmt(%9.3f))) starlevels(* 0.1 ** 0.05 *** 0.01) style(fixed) stats(N cdf rkf jp aic,  fmt(%9.2f)) mlabels(,titles)



